﻿using System;
using System.Collections;
using UnityEngine;

namespace USClientKernel.Template
{
    public class SingletonException : Exception
    {
        public SingletonException(string msg) : base(msg)
        {
        }
    }

    public abstract class Singleton<T> where T : class, new()
    {
        protected static T _Instance = null;

        public static T Instance
        {
            get
            {
                if (null == _Instance)
                {
                    _Instance = new T();
                }
                return _Instance;
            }
        }

        protected Singleton()
        {
            if (null != _Instance)
            {
                throw new SingletonException("This" + (typeof(T).ToString() + "Singleton Instance is not null !!!!!"));
            }
            Init();
        }

        protected virtual void Init()
        {
            Debug.Log("init");
        }
    }
}
